package uz.edo.app.client;

import java.util.Locale;

import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.behavior.HeaderContributor;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.resources.CompressedResourceReference;

import uz.edo.app.client.core.MyConstants;
import uz.edo.app.client.core.MySession;
import uz.edo.app.client.header.MyHeader;
import uz.edo.db.bean.Role;
import uz.edo.db.bean.User;

public abstract class MyPage extends Interface  implements MyConstants{
     private User user;
//     private static final CompressedResourceReference MYPAGE_JS = new CompressedResourceReference(MyPage.class, "MyPage.js");
    private static final CompressedResourceReference MYPAGE_CSS = new CompressedResourceReference(MyPage.class, "style/style.css");

    @SuppressWarnings({ "deprecation", "unchecked" })
	protected MyPage()
    {
 	super();
 	add(uzlink);
 	add(rulink);
 	add(HeaderContributor.forCss(MYPAGE_CSS));

// 	if( getSession().getLocale()!=LOCALE_RU && getSession().getLocale()!=LOCALE_UZ)
//	getSession().setLocale(LOCALE_RU);

 	MySession session = (MySession)getSession();
	if (!session.isLoged())
	throw new RestartResponseAtInterceptPageException(Login.class);
	else{
	user = session.getUser();
	}
		add(new MyHeader("myheader"));
    }

    public User getUser() {
        return user;
    }

    public Role getRole(String roleName){
        return  user.getRole(roleName);
    }

    public boolean isPrivileged(String privilege){
        return user.isPrivileged(privilege);
    }
	@Override
	public Locale getLocale() {
		return getSession().getLocale();
	}
}
